//
//  HMStatusToolBar.swift
//  微博
//
//  Created by 程双岐 on 16/9/23.
//  Copyright © 2016年 heima. All rights reserved.
//

import UIKit

class HMStatusToolBar: UIView {
    
    var statusViewModel: HMStadusViewModel?{
        didSet{
            
            retweetButton.setTitle(statusViewModel?.repostsCountContent, for: .normal)
            commentButton.setTitle(statusViewModel?.commentsCountContent, for: .normal)
            unlikeButton.setTitle(statusViewModel?.attitudesCountContent, for: .normal)
        }
        
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
//        backgroundColor = UIColor.black
        setupUI()
    }
    private lazy var retweetButton: UIButton = self.addChildButton(imageName: "timeline_icon_retweet", title: "转发")
    private lazy var commentButton: UIButton = self.addChildButton(imageName: "timeline_icon_comment", title: "评论")
    private lazy var unlikeButton: UIButton = self.addChildButton(imageName: "timeline_icon_unlike", title: "赞")
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){


        retweetButton.snp_makeConstraints { (make) in
            make.leading.equalTo(self)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(commentButton)
        }
        
        commentButton.snp_makeConstraints { (make) in
            make.leading.equalTo(retweetButton.snp_trailing)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(unlikeButton)
        }
        
        unlikeButton.snp_makeConstraints { (make) in
            make.leading.equalTo(commentButton.snp_trailing)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.trailing.equalTo(self)
        }
        
        let leftLineImage = addChildLineView()
        let rightLineImage = addChildLineView()
        
        leftLineImage.snp_makeConstraints { (make) in
            make.centerX.equalTo(retweetButton.snp_trailing)
            make.centerY.equalTo(self)
        }
        
        rightLineImage.snp_makeConstraints { (make) in
            make.centerX.equalTo(unlikeButton.snp_leading)
            make.centerY.equalTo(self)
        }
        
        
        
        

        
    }
    // 创建Button按钮

    
    
    
    private func addChildButton(imageName: String,title: String) -> UIButton{
        let button = UIButton()
        button.setImage(UIImage(named: imageName), for: .normal)
        button.setBackgroundImage(UIImage(named:"timeline_card_bottom_background"), for: .normal)
        button.setTitle(title, for: .normal)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        button.setTitleColor(UIColor.darkGray, for: .normal)
        button.adjustsImageWhenHighlighted = false
        addSubview(button)
        return button
    }
    
    private func addChildLineView() -> UIImageView{
        let lineImage = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        addSubview(lineImage)
        
        return lineImage
    }
}
